import datetime
import time

# 取上几天日期20:00:00 num 上几天
def getlastday(num):
    now_time = datetime.datetime.now()
    # 获取向上num时间
    last_time = now_time +datetime.timedelta(days=num)
    last_year = last_time.date().year
    last_month = last_time.date().month
    last_day = last_time.date().day

    last_time = datetime.datetime.strptime(str(last_year)+"-"+str(last_month)+"-"+str(last_day)+ " 20:00:00", "%Y-%m-%d %H:%M:%S")
    print(last_time)
    return last_time


# 取莫个日期上一天 20:00:00
#def getlastdayBydate(datestr):
    
#getlastday(1)

# 取今天20190214
def gettodayo():
    now_time = datetime.datetime.now()
    today_year = now_time.date().year
    today_month = now_time.date().month
    today_day = now_time.date().day
    todaystr = str(today_year)+str(today_month)+str(today_day)
    return todaystr


# 交易天数
def getjiaoyidnum(lastdnum):
    mylocalotime = time.localtime()
    xqj = time.strftime("%w", mylocalotime)
    jydunm = 0

    if xqj == '0':
        if lastdnum > 23:
            jydunm = lastdnum - 8
        elif lastdnum > 22:
            jydunm = lastdnum - 7.5
        elif lastdnum > 21:
            jydunm = lastdnum - 7
        elif lastdnum > 17:
            jydunm = lastdnum - 6
        elif lastdnum > 16:
            jydunm = lastdnum - 5.6
        elif lastdnum > 15:
            jydunm = lastdnum - 5
        elif lastdnum > 10:
            jydunm = lastdnum - 4
        elif lastdnum > 9:
            jydunm = lastdnum - 3.6
        elif lastdnum > 8:
            jydunm = lastdnum - 3            
        elif lastdnum > 2:
            jydunm = lastdnum - 2
        else:
            jydunm = 0

    elif xqj == '1':
        if lastdnum > 23:
            jydunm = lastdnum - 8
        elif lastdnum > 22:
            jydunm = lastdnum - 7.5
        elif lastdnum > 21:
            jydunm = lastdnum - 7
        elif lastdnum > 17:
            jydunm = lastdnum - 6
        elif lastdnum > 16:
            jydunm = lastdnum - 5.6
        elif lastdnum > 15:
            jydunm = lastdnum - 5
        elif lastdnum > 10:
            jydunm = lastdnum - 4
        elif lastdnum > 9:
            jydunm = lastdnum - 3.6
        elif lastdnum > 8:
            jydunm = lastdnum - 3            
        elif lastdnum > 3:
            jydunm = lastdnum - 2
        else:
            jydunm = 0.7

    elif xqj == '2':
        if lastdnum > 21:
            jydunm = lastdnum - 7.5
        elif lastdnum > 17:
            jydunm = lastdnum - 6
        elif lastdnum > 16:
            jydunm = lastdnum - 5.6
        elif lastdnum > 15:
            jydunm = lastdnum - 4.6
        elif lastdnum > 10:
            jydunm = lastdnum - 4
        elif lastdnum > 9:
            jydunm = lastdnum - 3.6
        elif lastdnum > 8:
            jydunm = lastdnum - 2.6
        elif lastdnum > 3:
            jydunm = lastdnum - 2
        elif lastdnum > 2:
            jydunm = lastdnum - 1.3            
        elif lastdnum > 1:
            jydunm = lastdnum - 0.3
        else:
            jydunm = lastdnum

    elif xqj == '3':
        if lastdnum > 24:
            jydunm = lastdnum - 7.5
        elif lastdnum > 19:
            jydunm = lastdnum - 6
        elif lastdnum > 18:
            jydunm = lastdnum - 5.6
        elif lastdnum > 17:
            jydunm = lastdnum - 4.6
        elif lastdnum > 12:
            jydunm = lastdnum - 4
        elif lastdnum > 11:
            jydunm = lastdnum - 3.6
        elif lastdnum > 10:
            jydunm = lastdnum - 2.6
        elif lastdnum > 5:
            jydunm = lastdnum - 2
        elif lastdnum > 4:
            jydunm = lastdnum - 1.3            
        elif lastdnum > 3:
            jydunm = lastdnum - 0.3
        else:
            jydunm = lastdnum

    elif xqj == '4':
        if lastdnum > 25:
            jydunm = lastdnum - 7.5
        elif lastdnum > 120:
            jydunm = lastdnum - 6
        elif lastdnum > 19:
            jydunm = lastdnum - 5.6
        elif lastdnum > 18:
            jydunm = lastdnum - 4.6
        elif lastdnum > 13:
            jydunm = lastdnum - 4
        elif lastdnum > 12:
            jydunm = lastdnum - 3.6
        elif lastdnum > 11:
            jydunm = lastdnum - 2.6
        elif lastdnum > 6:
            jydunm = lastdnum - 2
        elif lastdnum > 5:
            jydunm = lastdnum - 1.3            
        elif lastdnum > 4:
            jydunm = lastdnum - 0.3
        else:
            jydunm = lastdnum

    elif xqj == '5':
        if lastdnum > 26:
            jydunm = lastdnum - 7.5
        elif lastdnum > 21:
            jydunm = lastdnum - 6
        elif lastdnum > 20:
            jydunm = lastdnum - 5.6
        elif lastdnum > 19:
            jydunm = lastdnum - 4.6
        elif lastdnum > 14:
            jydunm = lastdnum - 4
        elif lastdnum > 13:
            jydunm = lastdnum - 3.6
        elif lastdnum > 12:
            jydunm = lastdnum - 2.6
        elif lastdnum > 7:
            jydunm = lastdnum - 2
        elif lastdnum > 6:
            jydunm = lastdnum - 1.3            
        elif lastdnum > 5:
            jydunm = lastdnum - 0.3
        else:
            jydunm = lastdnum
            
    elif xqj == '6':
        if lastdnum > 27:
            jydunm = lastdnum - 7.5
        elif lastdnum > 22:
            jydunm = lastdnum - 7
        elif lastdnum > 21:
            jydunm = lastdnum - 6.6
        elif lastdnum > 20:
            jydunm = lastdnum - 5.6
        elif lastdnum > 15:
            jydunm = lastdnum - 5
        elif lastdnum > 14:
            jydunm = lastdnum - 4.6
        elif lastdnum > 13:
            jydunm = lastdnum - 3.6
        elif lastdnum > 8:
            jydunm = lastdnum - 3
        elif lastdnum > 7:
            jydunm = lastdnum - 2.3
        elif lastdnum > 6:
            jydunm = lastdnum - 1.3            
        elif lastdnum > 1:
            jydunm = lastdnum - 1
        else:
            jydunm = 0

    return jydunm
